﻿using DomSharp.ExpressionVisitors;
using Microsoft.JSInterop;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace DomSharp
{
    public class DomQueryable : IQueryable
    {
        public DomQueryable(Expression expression)
        {
            Expression = expression;
        }
        public Type ElementType => throw new NotImplementedException();

        public Expression Expression { get; }

        public IQueryProvider Provider => throw new NotImplementedException();

        public IEnumerator GetEnumerator()
        {
            throw new NotImplementedException();
        }

        internal async ValueTask Execute()
        {
            DomExpressionVisitor domExpressionVisitor = new DomExpressionVisitor();
            var js = domExpressionVisitor.Translate(Expression);
            await Document.JSRuntime.InvokeVoidAsync("eval", js);
        }

        internal async ValueTask<T> Execute<T>()
        {
            DomExpressionVisitor domExpressionVisitor = new DomExpressionVisitor();
            var js = domExpressionVisitor.Translate(Expression);
           return await Document.JSRuntime.InvokeAsync<T>("eval", js);
        }
    }
}
